package com.dnjn.mes.biz.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnjn.mes.biz.domain.MesRecordBeat;
import com.dnjn.mes.biz.domain.MesRecordCapacity;
import com.dnjn.mes.biz.service.IMesRecordBeatService;
import com.dnjn.mes.common.core.controller.BaseController;
import com.dnjn.mes.common.core.domain.AjaxResult;
import com.dnjn.mes.common.utils.poi.ExcelUtil;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 节拍表 前端控制器
 * </p>
 *
 * @author Amber
 * @since 2023-07-26
 */
@RestController
@RequestMapping("/biz/mesRecordBeat")
public class MesRecordBeatController extends BaseController {

    @Autowired
    protected IMesRecordBeatService baseService;

    @GetMapping("/get/{id}")
    public AjaxResult get(@PathVariable Long id) {
        return success(baseService.getById(id));
    }

    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody MesRecordBeat domain) {
        domain.setCreateBy(getUsername());
        return toAjax(baseService.save(domain));
    }

    @PutMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody MesRecordBeat domain) {
        return toAjax(baseService.updateById(domain));
    }

    @DeleteMapping("/{pkIds}")
    public AjaxResult remove(@PathVariable Long[] pkIds) {
        baseService.removeBatchByIds(Arrays.asList(pkIds));
        return success();
    }

    @PostMapping("/page")
    public AjaxResult page(@RequestBody MesRecordBeat domain, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        Page page = Page.of(current, size);
        Page<MesRecordBeat> list = baseService.page(page, Wrappers.query(domain));
        return success(list);
    }

    @PostMapping("/export")
    public void export(HttpServletResponse response, MesRecordBeat domain) {
        List<MesRecordBeat> list = baseService.list(Wrappers.query(domain));
        ExcelUtil<MesRecordBeat> util = new ExcelUtil<MesRecordBeat>(MesRecordBeat.class);
        util.exportExcel(response, list, "参数数据");
    }




}